/*
 ============================================================================
 Name		: FaceRecognizer.h
 Author	  : Lenka Litvova
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CFaceRecognizer declaration
 ============================================================================
 */

#ifndef FACERECOGNIZER_H
#define FACERECOGNIZER_H

#include <e32base.h>	// For CActive, link against: euser.lib
#include <e32std.h>		// For RTimer, link against: euser.lib
#include <ncvImage.h> //NokiacVImage
#include "FaceGraph.h"
#include "Area.h"
#include "RecognitionObserver.h"

const TRgb KBlack = TRgb(0, 0, 0);
const TInt KErrorStep = -13;
const TInt KErrorCopy = -19; 

class CFaceRecognizer : public CActive
	{
public:
	// Cancel and destroy
	~CFaceRecognizer();

	// Two-phased constructor.
	static CFaceRecognizer* NewL(CNokiaCVImage *aImage, MRecognitionObserver *aObserver);

	// Two-phased constructor.
	static CFaceRecognizer* NewLC(CNokiaCVImage *aImage, MRecognitionObserver *aObserver);

public:
	// New functions
	// Function for making the initial request
	void StartL();
	
	/**
	 * Performs the next step (according to the actual recognition state) of recognition.
	 */
	TInt DoNextStepL();

	/**
	 * Returns the last created face graph.
	 */
	CFaceGraph* GetGraph();
	
private:
	// C++ constructor
	CFaceRecognizer(MRecognitionObserver *aObserver);

	// Second-phase constructor
	void ConstructL(CNokiaCVImage *aImage);
	
	/**
	 * Function called at the end of recognition.
	 */
	void FinishedL();

private:
	// From CActive
	// Handle completion
	void RunL();

	// How to cancel me
	void DoCancel();

	// Override to handle leaves from RunL(). Default implementation causes
	// the active scheduler to panic.
	TInt RunError(TInt aError);

private:
	TInt iRecognitionStep;//recognition step
	MRecognitionObserver::TRecognitionState iRecognitionState; //recognition process state
	TBool iCancel; //set to ETrue to break recognition process
	TInt iError;
	
	CFaceGraph *iFaceGraph;
	
	CNokiaCVImage *iImage;
	CNokiaCVImage *iFaceBW;
	CNokiaCVImage *iEdgeImage;
	CNokiaCVImage *iWorking;
	TSize iImageSize;
	CArea *iFaceArea;
	
	TBuf<500> iInfo;
	
	MRecognitionObserver *iObserver;
	};

#endif // FACERECOGNIZER_H
